package project.youkumenu;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import project.youkumenu.customview.GameView;
import project.youkumenu.utils.ShowViewUtils;

public class NewActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "aaaa";
    private int width_v;
    private int height_v;

    GameView gameView;

    private View viewHome;
    private ImageView ivMenu;
    private RelativeLayout rlLevel1;
    private RelativeLayout rlLevel2;
    private RelativeLayout rlLevel3;

    /**
     * 是否显示第三圆环
     * true:显示
     * false:隐藏
     */
    private boolean isShowLevel3 = true;

    /**
     * 是否显示第二圆环
     * true:显示
     * false:隐藏
     */
    private boolean isShowLevel2 = true;

    /**
     * 是否显示第一圆环
     * true:显示
     * false:隐藏
     */
    private boolean isShowLevel1 = true;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new);

        initView();
        viewClick();
    }

    private void initView() {
        gameView = (GameView) findViewById(R.id.game_view);
        viewHome = findViewById(R.id.view_home);
        ivMenu = (ImageView) findViewById(R.id.iv_menu);
        rlLevel1 = (RelativeLayout) findViewById(R.id.rl_level1);
        rlLevel2 = (RelativeLayout) findViewById(R.id.rl_level2);
        rlLevel3 = (RelativeLayout) findViewById(R.id.rl_level3);
    }

    private void viewClick() {
        gameView.setOnClickListener(this);
        viewHome.setOnClickListener(this);
        ivMenu.setOnClickListener(this);
        rlLevel1.setOnClickListener(this);
        rlLevel2.setOnClickListener(this);
        rlLevel3.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.game_view:
                width_v = view.getMeasuredWidth();
                height_v = view.getMeasuredHeight();
                Log.i(TAG, "width_v = " + width_v + ", height_v = " + height_v);
                Log.i(TAG, "getWidth = " + view.getWidth() + ", getHeight = " + view.getHeight());
                break;
            case R.id.view_home:
                //如果三级菜单和二级菜单是显示，都设置隐藏
                if (isShowLevel2) {
                    isShowLevel2 = false;
                    ShowViewUtils.hideView(rlLevel2);
                    if (isShowLevel3) {
                        isShowLevel3 = false;
                        ShowViewUtils.hideView(rlLevel3, 200);
                    }
                } else {
                    //如果都是隐藏，二级菜单显示
                    isShowLevel2 = true;
                    ShowViewUtils.showView(rlLevel2);
                }
                break;
            case R.id.iv_menu:
                if (isShowLevel3) {
                    //隐藏
                    isShowLevel3 = false;
                    ShowViewUtils.hideView(rlLevel3);
                } else {
                    //显示
                    isShowLevel3 = true;
                    ShowViewUtils.showView(rlLevel3);
                }
                break;
            case R.id.rl_level1:
                break;
            case R.id.rl_level2:
                break;
            case R.id.rl_level3:
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            //如果一级、二级、三级菜单是显示的就全部隐藏
            if (isShowLevel1) {
                isShowLevel1 = false;
                ShowViewUtils.hideView(rlLevel1);
                if (isShowLevel2) {
                    //隐藏二级菜单
                    isShowLevel2 = false;
                    ShowViewUtils.hideView(rlLevel2, 200);
                    if (isShowLevel3) {
                        //隐藏三级菜单
                        isShowLevel3 = false;
                        ShowViewUtils.hideView(rlLevel3, 400);
                    }
                }
            } else {
                //显示一级菜单
                isShowLevel1 = true;
                ShowViewUtils.showView(rlLevel1);
                //显示二级菜单
                isShowLevel2 = true;
                ShowViewUtils.showView(rlLevel2, 200);
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
